import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:ost_flutter_module/class/entity/store/store_home_banner_entity.dart';
import 'package:ost_flutter_module/common/adapt.dart';
import 'package:ost_flutter_module/common/color.dart';

class SwiperWidget extends StatelessWidget {
  final List<StoreHomeBannerEntity> swiperList;
  final ValueChanged<String> onTap;
  const SwiperWidget({
    Key key,
    this.onTap,
    this.swiperList,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(Adapt.px(10)),
      ),
      height: Adapt.px(200),
      child: Swiper(
        autoplay: true,
        viewportFraction: 0.95,
        scale: 0.95,
        outer: false,
        itemCount: swiperList.length,
        itemBuilder: (context, index) {
          return InkWell(
              child: Container(
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(10),
                  image: DecorationImage(
                    image: NetworkImage(swiperList[index].img),
                    fit: BoxFit.cover,
                  ),
                ),
              ),
              onTap: () {
                onTap(swiperList[index].link ?? '');
              });
        },
        pagination: SwiperPagination(
          builder: DotSwiperPaginationBuilder(
            color: Colors.white,
            activeColor: colorFACD33,
            size: 8.0,
            activeSize: 8.0,
          ),
        ),
      ),
    );
  }
}
